package com.fzc.rhinooffice.common.utils;


import android.annotation.SuppressLint;
import android.content.Context;
import android.util.JsonReader;
import android.widget.Toast;

import com.fzc.rhinooffice.common.SysApplication;

import java.io.StringReader;
import java.text.SimpleDateFormat;
import java.util.Calendar;

@SuppressLint("NewApi")
public class StringUtil {

	public static boolean isEmpty(String str){

		if(str==null || "".equals(str)){

			return true;
		}

		return false;
	}

	public static void showToast(Context context,String content){
		Toast.makeText(context, content, Toast.LENGTH_SHORT).show();
	}

	public static void showToast(String content){
		Toast.makeText(SysApplication.mContext, content, Toast.LENGTH_SHORT).show();
	}

	public static JsonReader StringToJsonReader(String str){
		return new JsonReader(new StringReader(str));
	}

	/**
	 * 把驼峰结构的字符串分离出来，例如ListView,分离成List和View
	 * */
	public static String[] getWordsFromString(String string){
		String[] names = string.replaceAll("[A-Z]"," $0").replaceFirst(" ","").split(" ");
//		for (String name:names) LogUtils.e("分离："+name);
		return names;
	}
	
	/**
	 * 
	 * @param rule	时间显示格式
	 * @return 当前时间
	 */
	public static String getCurrentTimeStr(String rule){
		SimpleDateFormat sdf;
		if(rule==null){
			sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
		}else{
			sdf = new SimpleDateFormat(rule);
		}
		return sdf.format(Calendar.getInstance().getTime());
	}
	
}
